package com.byzx.wine.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;





import com.byzx.wine.po.Winetype;
import com.byzx.wine.service.IWineTypeService;
import com.byzx.wine.util.Page;


@Controller
@RequestMapping(value ="winetype")
public class WinetypeAction {
@Autowired
private IWineTypeService winetypeService;
@RequestMapping("Winetype")
public String login(HttpServletResponse response, HttpServletRequest request) {
	return "winetype/winetype";
}

@RequestMapping("findwinetype")
@ResponseBody
public Map<String, Object> findPage(Model model, Integer iDisplayLength,
		Integer sEcho, Integer iDisplayStart) {
	if (sEcho == null) {
		sEcho = 1;
	}
	if (iDisplayLength == null) {
		iDisplayLength = 10;
	}
	if (iDisplayStart == null) {
		iDisplayStart = 1;
	}
	Map<String, Object> map = new HashMap<String, Object>();
	Page<Map<String, Object>> page = new Page<Map<String, Object>>(
			iDisplayStart, iDisplayLength, map);
	Page<Map<String, Object>> page1 = winetypeService.findPage(page);

	map.put("sEcho", sEcho);
	map.put("iTotalRecords", page1.getTotalCount());
	map.put("iTotalDisplayRecords", page1.getTotalCount());
	map.put("aaData", page1.getList());
	return map;
}

//显示数据
	@RequestMapping("/selectByPrimaryKey")
	@ResponseBody
	public Map<String, Object> selectByPrimaryKey(Integer id) {
		System.out.println("1111111");
		Map<String, Object> map=winetypeService.selectByPrimaryKey(id);
		return map;
	}
	
	@RequestMapping("/winedelete")
	@ResponseBody
	public Map<String, Object> userdelete(Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		int num = winetypeService.deleteByPrimaryKey(id);
		map.put("num", num);
		return map;
	}
	
	//添加
		@RequestMapping("wineadd")
		@ResponseBody
		public Map<String, Object> useradd(Winetype wine) {
			System.out.println(wine.getName());
			System.out.println(wine.getId());
			System.out.println(wine.getTypedetail());
			System.out.println("=========");
			Map<String, Object> map = new HashMap<String, Object>();
			int num = winetypeService.insert(wine);
			map.put("num", num);
			return map;
		}
		
		
		//修改数据
		@RequestMapping("/wineupdate")
		@ResponseBody
		public Map<String, Object> userupdate(Winetype wine) {
	   System.out.println(wine.getId());
	   Integer num=winetypeService.updateByPrimaryKey(wine);
			Map<String, Object> map = new HashMap<String, Object>();
	
			map.put("num", num);
			return map;
		}
		
		@RequestMapping("/winedeletes")
		@ResponseBody
		public Map<String, Object> roledeletes(String ids) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("flag", winetypeService.deleteAll(ids));
			return map;
		}
}
